<?php
// get_user_info.php
if (isset($_GET['id'])) {
    $userId = intval($_GET['id']);  // 获取用户ID并转换为整数

    // 连接数据库
    $servername = "localhost";
    $db_username = "root";
    $db_password = "123456";
    $dbname = "test";

    $conn = new mysqli($servername, $db_username, $db_password, $dbname);

    if ($conn->connect_error) {
        echo json_encode(array("status" => "error", "message" => "数据库连接失败"));
        exit;
    }

    // 根据id查询用户数据
    $sql = "SELECT id, username, email, school, phone, classRoom FROM student WHERE id = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("i", $userId);
    $stmt->execute();
    $result = $stmt->get_result();

    if ($result->num_rows > 0) {
        $user = $result->fetch_assoc();
        echo json_encode(array(
            "status" => "success",
            "data" => $user
        ));
    } else {
        echo json_encode(array("status" => "error", "message" => "未找到该用户"));
    }

    $stmt->close();
    $conn->close();
} else {
    echo json_encode(array("status" => "error", "message" => "无效的用户ID"));
}
?>
